package com.RedRiver.hospitalsystem.personal_service.app.controller;


import cn.hutool.core.bean.BeanUtil;
import com.RedRiver.hospitalsystem.personal_service.common.Personal_serviceResultCode;
import com.RedRiver.hospitalsystem.personal_service.common.exception.AccountException;
import com.RedRiver.hospitalsystem.personal_service.common.exception.DoctorException;
import com.RedRiver.hospitalsystem.personal_service.infra.model.Account;
import com.RedRiver.hospitalsystem.personal_service.infra.model.Doctor;
import com.RedRiver.hospitalsystem.personal_service.service.DoctorService;
import com.RedRiver.hospitalsystem.personal_service.service.Form.*;
import com.RedRiver.hospitalsystem.personal_service.service.info.AccountInfo;
import com.RedRiver.hospitalsystem.personal_service.service.info.AccountPageInfo;
import com.RedRiver.hospitalsystem.personal_service.service.info.DoctorInfo;
import com.RedRiver.hospitalsystem.personal_service.service.info.DoctorPageInfo;
import com.RedRiver.hospitalsystem.result.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@RestController
@RequestMapping("/doctor")
@Api(tags = "医生管理接口")
public class DoctorController {

    @Resource
    private DoctorService doctorService;

    @ApiOperation("根据id查看医生信息")
    @GetMapping("/findDoctor/{doctorId}")
    public Result<DoctorInfo> findDoctor(@ApiParam("请输入需要查询的Id") @PathVariable("doctorId") Integer doctorId){
        Doctor doctor = doctorService.getOne(new QueryWrapper<Doctor>().eq("doctor_id", doctorId));
        if (doctor == null) throw new DoctorException(Personal_serviceResultCode.DOCTOR_NOT_EXISTED);
        return Result.getInstance(DoctorInfo.class).setCode(200).setMsg("查询成功").setData(BeanUtil.copyProperties(doctor, DoctorInfo.class));
    }

    @ApiOperation("分页查看所有医生信息")
    @PostMapping("/findAllDoctor")
    public Result<IPage> findAllDoctor(@RequestBody PageForm form){
        IPage<DoctorPageInfo> byPage = doctorService.findPageAllDocktor(form);
        return  Result.getInstance(IPage.class).setMsg("分页成功").setData(byPage);
    }

    @ApiOperation("分页根据部门查询医生")
    @PostMapping("/FindDepartmentDoctor")
    public Result<IPage> FindDepartmentDoctor(@RequestBody DoctorDepartmentForm doctorDepartmentForm){
        IPage<DoctorPageInfo> byPage = doctorService.findPageDepartmentDocktor(doctorDepartmentForm);
        return  Result.getInstance(IPage.class).setMsg("分页成功").setData(byPage);
    }

    @ApiOperation("分页根据医生级别查询医生")
    @PostMapping("/FindLevelDoctor")
    public Result<IPage> FindLevelDoctor(@RequestBody DoctorLevelForm doctorLevelForm){
        IPage<DoctorPageInfo> byPage = doctorService.FindPageLevelDoctor(doctorLevelForm);
        return  Result.getInstance(IPage.class).setMsg("分页成功").setData(byPage);
    }

    @ApiOperation("新增医生信息")
    @PostMapping("/createDoctor")
    public Result<?> createDoctor(@RequestBody DoctorForm doctorForm){
        return doctorService.createDoctor(doctorForm);
    }

    @ApiOperation("修改医生信息")
    @PostMapping("/updateDoctor")
    public Result<String> changeDoctor(@RequestBody DoctorChangeForm doctorChangeForm){
        return doctorService.changeDoctor(doctorChangeForm);
    }

    @ApiOperation("根据id删除医生信息")
    @PostMapping("/deleteDoctor/{doctorId}")
    public Result<?> delDoctor(@ApiParam("请输入需要删除的Id") @PathVariable("doctorId") Integer doctorId){
        return doctorService.delDoctor(doctorId);
    }

}

